package fem2.observer;

import java.io.IOException;

import fem2.Model;
import fem2.enu.StressType;

public class GidStressObserver extends GidStructuralObserver {

	private StressType stressType = StressType.CAUCHY_STRESS;

	public GidStressObserver(Model m, TimeStepObserver o, String projectDir, String projectName) {
		super(m, o, projectDir, projectName);
	}

	public GidStressObserver(Model m, TimeStepObserver o, String projectDir, String projectName,
			String fileName) {
		super(m, o, projectDir, projectName, fileName);
	}

	public GidStressObserver(Model m, TimeStepObserver o, String projectDir, String projectName,
			StressType stressType) {
		super(m, o, projectDir, projectName);
		this.stressType = stressType;
	}

	public GidStressObserver(Model m, TimeStepObserver o, String projectDir, String projectName,
			String fileName, StressType stressType) {
		super(m, o, projectDir, projectName, fileName);
		this.stressType = stressType;
	}

	@Override
	public void fireStarted() {
	}

	@Override
	public void fireTimeStepStarted() {
	}

	@Override
	public void fireIterationStarted() {
	}

	@Override
	public void fireIterationFinished() {
	}

	@Override
	public void fireTimeStepFinished() {
		double timeStep = timeStepObserver.getCurrentTimeStep();

		try {
			gidPost.writeMesh(m, timeStep);
			gidPost.writeGaussPointStressResults(m, timeStep, stressType);
		} catch (IOException e) {
			throw new Error("Write failed: " + e.getMessage());
		}
	}

	@Override
	public void fireFinished() {
	}

}
